window.onload = function() {
    // var userid = getCookie('userid')
    let userid=localStorage.getItem('userid')
    if(!userid) {
        popup.msg('请先登录！')
        localStorage.setItem('url', location.href)
        location.href = './login.html'
        return false
    }
    var toprev = document.querySelector('.toprev')
    // toprev.onclick = () => history.back()
    toprev.onclick = () => location.href = './index.html'
    request({
        url: 'http://localhost:3000/front/api/orders/getall/' + userid,
        headers: {
            authorization: localStorage.getItem('token')
        }
    }).then(res => {
        console.log(res);
        let {error_code, msg} = res
        var orderlist = document.querySelector('.orders ul')
        if(error_code === 0) {
            var orderhtml = ''
            res.data.forEach(item => {
                orderhtml += `
                    <li>
                        <p>
                            <span>订单号：${item.orderno} <i>图标</i></span> 
                            <span>支付成功</span>
                        </p>
                        <p>日期：2023.01.07 12:10:12</p>
                        <p>
                            <i>${item.mode}</i>
                            <span>${item.menuname}等一件商品</span>
                            <b>${item.totalprice}</b>
                        </p>
                        <p>取餐码：${item.code}</p>
                    </li>
                `
            })
            orderlist.innerHTML = orderhtml
        }
    })
}